package jhelp;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;

public class FileDataProcessor implements DataProcessor{

	
	public Hashtable<String, Record> dispatchDataInHashtable(String dataSourcePath) {
		File file = new File(dataSourcePath);
		Hashtable<String, Record> dataTable= new Hashtable<String, Record>();
		BufferedReader fileReader = null;
		try {
			fileReader = new BufferedReader(new FileReader(file));
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String line = null;
		try {
			line = fileReader.readLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int i = 1;
		int id = 0;
		while(line != null){
			if(i%2 == 1 && line.length()>2){
				try {
					Record rec = new Record(id, line, fileReader.readLine());
					dataTable.put(line, rec);
					id++;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			try {
				line = fileReader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return dataTable;
	}
}